package com.haiyi.activiti.engine.framework.basic;

import java.util.Map;

/**
 * <p> </p>
 *
 * <pre> Created: 2018/12/7 16:23 </pre>
 *
 * @author hlu
 * @version 1.0
 * @since JDK 1.7
 */
public class ResponseData<T> {

    /**
     * 响应状态
     */
    private int status;

    /**
     * 响应失败返回的消息
     */
    private String message;

    /**
     * 响应成功返回数据
     */
    private T data;

    /**
     * 扩展信息
     */
    private Map<String,Object> extInfo;

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    public ResponseData(int status, String message) {
        this.status = status;
        this.message = message;
    }

    public ResponseData(int status, T data) {
        this.status = status;
        this.data = data;
    }

    public ResponseData(int status, T data,Map<String,Object> extInfo) {
        this.status = status;
        this.data = data;
        this.extInfo = extInfo;
    }


    /**
     * 响应成功
     * @param data
     * @param <T>
     * @return
     */
    public static <T> ResponseData<T> ok(T data){
        return new ResponseData<>(ResponseStatus.SUCCESS,data);
    }

    /**
     * 响应成功
     * @param data
     * @param <T>
     * @return
     */
    public static <T> ResponseData<T> ok(T data,Map<String,Object> extInfo){
        return new ResponseData<>(ResponseStatus.SUCCESS,data,extInfo);
    }
    /**
     * 响应失败
     * @param msg
     * @param <T>
     * @return
     */
    public static <T> ResponseData<T> error(String msg){
        return new ResponseData<>(ResponseStatus.ERROR,msg);
    }


    public Map<String, Object> getExtInfo() {
        return extInfo;
    }

    public void setExtInfo(Map<String, Object> extInfo) {
        this.extInfo = extInfo;
    }

    public interface ResponseStatus{
        int SUCCESS = 200;
        int ERROR = 500;
    }
}
